package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.JobData;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.PersonCountOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.toList;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption empJobData() {
        //查询到职位人数
        List<JobData> jobDataList = empMapper.empJobData();
        //解析并封装到JobOption里
        JobOption jobOption = new JobOption();
        // 把数据库查询到数据对象转成字符串集合，存放的职位名称
        List<String> jobList = jobDataList.stream().map(JobData::getJob).toList();
        jobOption.setJobList(jobList);//["教研主管","学工主管","其他","班主任","咨询师","讲师"],List<String>
        // 把数据库查询到数据对象转成数字集合，存放的职位人数
        List<Integer> countList = jobDataList.stream().map(JobData::getCount).toList();
        jobOption.setDataList(countList);//[1,1,2,6,8,13]
        return jobOption;
    }

    /**
     * 员工性别人数统计
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> empGenderData() {
        //1.查询数据
        List<Map<String,Object>> dataList = empMapper.empGenderData();
        //2.封装List<Map<String,Object>>
        return dataList;
    }

    /**
     * 学生学历人数统计
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> countStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    /**
     * 班级人数统计
     * @return
     */
    @Override
    public PersonCountOption countClazzData() {
        //班级列表
        List<Map<String ,Object>> list =studentMapper.countClazzData();
        //班级名称
        List<String> clazzList = list.stream().map(map -> map.get("name").toString()).toList();
        //班级人数
        List<Object> dataList = list.stream().map(map -> map.get("value")).toList();
        return new PersonCountOption(clazzList,dataList);
    }
}
